package com.ecy.quadratic.ui.fragment;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ecy.quadratic.R;
import com.ecy.quadratic.beans.user.User;
import com.ecy.quadratic.manager.LoginManager;
import com.ecy.quadratic.reader.base.BaseFragment;
import com.ecy.quadratic.reader.component.AppComponent;
import com.ecy.quadratic.ui.activity.AboutActivity;
import com.ecy.quadratic.ui.activity.BrowserActivity;
import com.ecy.quadratic.ui.activity.CollectActivity;
import com.ecy.quadratic.ui.activity.LoginActivity;
import com.ecy.quadratic.ui.activity.ProfileActivity;
import com.yuyh.easyadapter.glide.GlideCircleTransform;

import butterknife.Bind;
import butterknife.OnClick;

public class MineFragment extends BaseFragment {

    @Bind(R.id.portrait_iv)
    ImageView mPortraitIV;
    @Bind(R.id.tv_nickname)
    TextView mNicknameTV;

    User mUser;

    public MineFragment() {
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    public void attachView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void configViews() {

    }

    @Override
    public void onStart() {
        super.onStart();
        mUser = LoginManager.getInstance().getUser();
        if (mUser != null) {
            Glide.with(this).load(mUser.portrait).centerCrop().bitmapTransform(new GlideCircleTransform(getContext())).into(mPortraitIV);
            mNicknameTV.setText(mUser.nickname);
            if (mUser.gender.equals("男")) {

                mNicknameTV.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.drawable.male), null);
            } else {
                mNicknameTV.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.drawable.female), null);
            }
        }
    }

    @OnClick(R.id.mine_browser_llt)
    void enterBrowser() {
        BrowserActivity.startActivity(getContext());
    }

    @OnClick(R.id.mine_collect_llt)
    void enterCollect() {
        CollectActivity.startActivity(getContext());
    }

    @OnClick(R.id.settings_llt)
    void enterSettings() {
        AboutActivity.startActivity(getContext());
    }

    @OnClick(R.id.portrait_iv)
    void login() {
        if (mUser == null) {
            LoginActivity.startActivity(getContext());
        } else {
            ProfileActivity.startActivity(getContext());
        }

    }

}
